package com.util;

import com.entity.common.User;
import com.entity.xsxt.Student;
import org.apache.shiro.crypto.hash.SimpleHash;
import org.apache.shiro.util.ByteSource;

/**
 * Created by Administrator on 2019/3/4.
 */
public class Md5Util {

    public static void setHex(User user){
        if(user.getAccount()!=null&&user.getPassword()!=null){
            String hashAlgorithmName = "MD5";
            Object credentials = user.getPassword();
            ByteSource admin = ByteSource.Util.bytes(user.getAccount());
            int hashIterations = 520;
            SimpleHash simpleHash  = new SimpleHash(hashAlgorithmName, credentials, admin, hashIterations);
            user.setPassword(simpleHash.toHex());
        }
    }

    public static void setHex(Student student){
            String hashAlgorithmName = "MD5";
            Object credentials = student.getPassword();
            ByteSource admin = ByteSource.Util.bytes(student.getStuNo());
            int hashIterations = 520;
            SimpleHash simpleHash  = new SimpleHash(hashAlgorithmName, credentials, admin, hashIterations);
            student.setPassword(simpleHash.toHex());
    }
}
